#include "myhead.h" 

char* delim=" \n";
char* helpStr=
"Syntax: exit\nSyntax: cd directory\nSyntax: dir [directory]\nSyntax: del file\nSyntax: ren srcfile dstfile\nSyntax: cop srcfile dstfile\n";

enum CommandType
{
	ExitType, CDType, DirType, DelType, RenType, CopyType, PrintType
};
//exit退出 、cd 切换目录 、dir 显示文件夹下目录（ls）、era删除、 ren重命名、cop复制 、disp （echo）
char* commandStr[CommandNumber]=
{
	"exit", "cd", "dir", "era", "ren", "cop","disp"
};

void (*commandArray[CommandNumber])(char* params[], int paramNumber)=
{
	exitShell, changeDir, listDir, delFile, renFile, copyFile,printShell
};

int main(int argc, char* argv[])
{
	char buf[MaxCommandLine];
	int n, paramNumber;
	int commandType;
	char* params[4];
	printPrompt();
	while ((n=read(STDIN_FILENO, buf, MaxCommandLine))>0)
	{
		buf[n]='\0';
		commandType=parseCommand(buf, params, &paramNumber);
		if (commandType==-1)
		{
			printf("illegal command\n%s");
		}
		else
		{
			commandArray[commandType](params, paramNumber);			
		}
		printPrompt();
	}
	return 0;
}
